class LevelRequire {

    public reqElements: LevelRequirelElement[];

    public constructor() {
        this.reqElements = [];
    }

    public getLevelReqCount(): number {
        return this.reqElements.length;
    }

    public addElement(type: string, num: number) {
        let ele: LevelRequirelElement = new LevelRequirelElement();
        ele.type = type;
        ele.num = num;
        this.reqElements.push(ele);
    }

    public openChange() {
        this.reqElements = [];
    }

    public changeReqNum(type: string, num: number) {
        let count: number = this.getLevelReqCount();
        for (let i = 0; i < count; i++) {
            if (this.reqElements[i].type == type) {
                this.reqElements[i].num -= num;
                return;
            }
        }
    }

    public isClear(): boolean {
        for (let i in this.reqElements) {
            if (this.reqElements[i].num > 0) {
                return false;
            }
        }
        return true;
    }
}